package com.jackrain.nea.omslocal.task;

import com.jackrain.nea.config.PropertiesConf;
import com.jackrain.nea.omslocal.service.QiMenPosDeliveryorderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Discription: 发送 创建发货单数据 任务
 * Created with IntelliJ IDEA.
 * @Author cs
 * @Date 2018/3/21 14:21
 */
@Component
@Slf4j
public class AutoQiMenPosDeliceryOrderCreat {

    @Autowired
    private QiMenPosDeliveryorderService qmdocs;

    @Autowired
    private PropertiesConf pconf;

    /**
     * 扫描创建发货单任务
     */
    public void getScheduledExecutorSendA() {
        log.info("AutoMotThreads QiMenDeliceryOrderCreat started !!!");
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    qmdocs.posDeliceryOrderCreatStart();

                } catch (Exception e) {
                    e.printStackTrace();
                    // 执行任务错误,将日志记录
                }
            }
        };
        ScheduledExecutorService service = Executors
                .newSingleThreadScheduledExecutor();
        // 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
        // 正式 要延迟适当时间,以便时间初始化赋值
        service.scheduleAtFixedRate(runnable, 10, pconf.getPropertyInt("ons.deliceryTime"), TimeUnit.SECONDS);
    }

    /**
     * 创建发货单失败，再发送
     */
    public void getScheduledExecutorSendAgainA() {
        log.info("AutoMotThreads QiMenDeliceryOrderCreat Send Again started !!!");
        Runnable runnable = new Runnable() {

            @Override
            public void run() {
                try {


                } catch (Exception e) {
                    e.printStackTrace();
                    // 执行任务错误,将日志记录
                }
            }
        };
        ScheduledExecutorService service = Executors
                .newSingleThreadScheduledExecutor();
        // 第二个参数为首次执行的延时时间，第三个参数为定时执行的间隔时间
        // 正式 要延迟适当时间,以便时间初始化赋值
        service.scheduleAtFixedRate(runnable, 1, pconf.getPropertyInt("ons.deliceryTime"), TimeUnit.MINUTES);
    }

}
